﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace CreateList {
    /// <summary>
    /// Interaction logic for MainWindow.xaml
    /// </summary>
    public partial class MainWindow : Window {
        public MainWindow() {
            InitializeComponent();

            if (Clipboard.ContainsText())
            {
                InputBox.Text = Clipboard.GetText();
            }
        }

        private void InputBox_Click(object sender, RoutedEventArgs e)
        {
            if (InputBox.Text == "Input")
            {
                InputBox.Text = "";
            }
        }

        private void Convert_Click(object sender, RoutedEventArgs e)
        {
            Convert("ul");
        }

        private void Convert(string tag)
        {
            string open = "";
            string close = "";

            if (tag == "ul")
            {
                open = "<ul>";
                close = "</ul>";
            }
            if (tag == "ol")
            {
                open = "<ol>";
                close = "</ol>";
            }
            
            OutputBox.Text = "";

            var sb = new StringBuilder();

            sb.AppendLine(open);

            var lines = InputBox.Text.Split(new string[] { Environment.NewLine }, StringSplitOptions.None);

            foreach (var line in lines) {
                if (string.IsNullOrEmpty(line) || string.IsNullOrWhiteSpace(line)) {
                    continue;
                }
                sb.AppendLine("\t\t<li>\r\n\t\t\t" + line.Substring(line.IndexOf("\t")) + "\r\n\t\t</li>");
            }

            sb.AppendLine("\t" + close);

            OutputBox.Text = sb.ToString();
        }

        private void MakeOL(object sender, RoutedEventArgs e)
        {
            Convert("ol");
        }
    }
}
